package com.china08.yxyapi.api.home.activity.marker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.db.maker.YxyMakerWorks;
import com.china08.yxyapi.repository.db.marker.YxyMakerWorksRepository;

/**
 * 报名列表-下载包
 * 
 */
@CrossOrigin
@RestController
public class WorksZipDownloadController {

    @Value("${yxy.res.url}")
    private String yxy_res_url;

    @Autowired
    private YxyMakerWorksRepository yxyMakerWorksRepository;

    @RequestMapping(value = "/api_yw/home/marker/works/zipdownload/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object process(HttpServletRequest request, HttpServletResponse response,
            @PathVariable(value = "id") String id) {
        RespModel model = new RespModel();
        YxyMakerWorks work = yxyMakerWorksRepository.findOne(id);
        // 打包下载url
        String zipurl = yxy_res_url + "/res/downloadHrbMaker/" + work.getId() + "?downloadFilename=" + work.getName()
                + "&registerFilename=" + work.getRegisterFileName() + "&worksFilename=" + work.getWorksFileName()
                + "&worksFileLocation=" + work.getWorksFile() + "&registerFileLocation=" + work.getRegisterFile();
        model.zipdownloadLocation = zipurl;
        return model;
    }

    protected static class RespModel {
        // 打包下载url
        public String zipdownloadLocation;
    }
}
